package com.hcinfos.gsoo.adapter;

import java.util.List;

import com.hcinfos.gsoo.R;
import com.hcinfos.gsoo.enity.WType;

import android.content.Context;
import android.graphics.Bitmap;
import android.graphics.Color;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

public class MenuAdapter extends BaseAdapter {

	private List<WType> list;
	private LayoutInflater mInflater;
	public Context context;
	private int position = 0;

	public MenuAdapter(Context context, List<WType> list) {
		this.list = list;
		this.context = context;
		mInflater = LayoutInflater.from(context);
	}

	@Override
	public int getCount() {
		return list.size();
	}

	@Override
	public Object getItem(int position) {
		return list.get(position);
	}

	@Override
	public long getItemId(int arg0) {
		return arg0;
	}

	@Override
	public View getView(int position, View convertView, ViewGroup parent) {
		final Holder holder;
		if (convertView == null) {
			convertView = mInflater.inflate(R.layout.menu_view, null);
			holder = new Holder();
			holder.nameTv = (TextView) convertView
					.findViewById(R.id.menu_name_tv);
			holder.view = convertView;
			convertView.setTag(holder);
		} else {
			holder = (Holder) convertView.getTag();
		}
		if (this.position == position) {
			holder.view.setBackgroundColor(Color.WHITE);
		} else {
			holder.view.setBackgroundColor(Color.parseColor("#E9FAFC"));
		}

		WType type = list.get(position);
		holder.nameTv.setText(type.getTypeName());
		return convertView;
	}

	private final class Holder {
		TextView nameTv;
		View view;

	}

	public void setSelect(int position) {
		this.position = position;
		notifyDataSetChanged();
	}

	public void setDataChange(List<WType> list) {
		this.list = list;
		notifyDataSetChanged();
	}

}
